﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Z2102WinForms.SY
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();

            panel1.Visible = false;
            buttonConsole.Click += delegate
            {
                Program.ExecConsoleApp("Z2102Console.SY.Class2");
            };
            buttonWinForms.Click += delegate
            {
                panel1.Visible = true;
                ShowResult();
            };
        }

        private void ShowResult()
        {
            string result = "";
            for (int i = 2; i <= 1000; i++)
            {
                int s = 1;
                string str = "1";
                for (int j = 2; j <= (int)Math.Sqrt(i); j++)
                {
                    if (j * (i / j) == i)
                    {
                        if (j != i / j)
                        {
                            s += j + i / j;
                            str += string.Format("+{0}+{1}", j, i / j);
                        }
                        else
                        {
                            s += j;
                            str += string.Format("+{0}", j);
                        }
                    }
                }
                if (s == i) result += string.Format("{0}={1}\r\n", i, str);
            }
            label2.Text = result;
        }
    }
}
